package main

import (
	"fmt"
	"runtime"
	"time"
)

func main() {
	//goroutineTest()
	cpuNumTest()
}

func goroutineTest() {
	go helloWorld("goroutine1")
	go helloWorld("goroutine2")
	go helloWorld("goroutine3")
	helloWorld("main")
}

func helloWorld(name string) {
	go helloGolang(name + " goroutine1")
	go helloGolang(name + " goroutine2")
	go helloGolang(name + " goroutine3")
	for i := 1; i <= 10; i++ {
		fmt.Printf("[%s]hello, world: %d\n", name, i)
		time.Sleep(time.Second)
	}
}

func helloGolang(name string) {
	for i := 1; i <= 10; i++ {
		fmt.Printf("[%s]hello, golang: %d\n", name, i)
		time.Sleep(time.Second)
	}
}

func cpuNumTest() {
	fmt.Println(runtime.NumCPU())
	runtime.GOMAXPROCS(10)
}
